/*
* 如果你需要使用store，只需要把下面的代码取消注释即可
*/

/* import Vue from 'vue'
import moduleStore from '../../store'
import { Store } from 'vuex'

let store!: Store<any>

if (Vue.prototype.isPortal) {
    store = window[window.poolName].store
} else {
    store = moduleStore as Store<any>
}

const scopeName = process.env.APP_SCOPE_NAME

function commit (funcStr: string, data: any) {
    store.commit(`${scopeName}/${funcStr}`, data)
} */

interface WS {
    onclose: (event?: CloseEvent) => void;
    onmessage: (event: MessageEvent) => void;
    onopen?: (event?: Event) => void;
    onerror?: (event?: Event) => void;
}

const ws: WS = {
    // onopen (event) {
    //     // 当 readyState === 'OPEN' 时,会执行这里
    // },
    onerror (error) {
        console.log('websocket connect is error...', error)
        // 当websocket出错时,会执行这里
    },
    onmessage (event) {
        // websocket接收到推送的消息
        let message = JSON.parse(event.data)
        if (!message) {
            return
        }
        console.log(message)
    },
    onclose (event) {
        // 当 readyState === 'CLOSED' 时,会执行这里
        console.log('websocket connect is closed...')
    }
}

export default ws
